package com.franklin.ideaplugin.mybatisrunner.xml.params;

import cn.hutool.core.util.StrUtil;
import com.franklin.ideaplugin.mybatisrunner.event.events.AbstractSqlEvent;
import com.franklin.ideaplugin.mybatisrunner.utils.MyStringUtils;
import com.intellij.psi.PsiElement;
import lombok.Data;

import javax.swing.*;

/**
 * @author Ye Junhui
 * @since 2024/2/20
 */
@Data
public abstract class MybatisParam {

    /**
     * 获取El表达式
     * @return
     */
    protected String elExpression;

    /**
     * 参数名称
     */
    protected String paramName;

    /**
     * 是否可见
     */
    protected boolean visible = true;

    protected final PsiElement psiElement;

    public MybatisParam(PsiElement psiElement) {
        this.psiElement = psiElement;
    }

    /**
     * ui组件
     * @return
     */
    public abstract JComponent buildComponent(Runnable action);

    /**
     * 构建事件
     * @return
     */
    public abstract AbstractSqlEvent buildEvent();

    /**
     * 加载
     *
     * @param cache
     */
    public abstract void load(String cache);

    /**
     * 设置el表达式
     * @param elExpression
     */
    public void setElExpression(String elExpression){
        this.elExpression = elExpression;
        this.paramName = MyStringUtils.resolveParamName(elExpression);
    }
}
